package com.company.nuwa.common.utils;

/**
 * <p>数字混淆工具</p >
 *
 * @author youyoukele
 * @version 1.0
 * @date 2023/3/8 上午10:53
 */
public class NumberObfuscationUtil {

    /**
     * 正向混淆方法(转为16进制字符串)
     *
     * @param num
     * @return
     */
    public static String obfuscate(long num) {
        return Long.toHexString(num);
    }

    /**
     * 逆向混淆方法(16进制字符串转换为数字)
     *
     * @param obfuscatedStr
     * @return
     */
    public static long deobfuscate(String obfuscatedStr) {
        return Long.parseLong(obfuscatedStr, 16);
    }

    public static void main(String[] args) {
        long num = 1632662208699695114L;
        String obfuscatedStr = NumberObfuscationUtil.obfuscate(num);
        long deobfuscatedNum = NumberObfuscationUtil.deobfuscate(obfuscatedStr);

        System.out.println("原始数字：" + num);
        System.out.println("混淆后的字符串：" + obfuscatedStr);
        System.out.println("还原后的数字：" + deobfuscatedNum);
    }
}
